﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ReconSite.Master" AutoEventWireup="true"
    CodeBehind="MatchInvoice.aspx.cs" Inherits="ReconUI.MatchInvoice" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleHolder" runat="server">
    <title>Match Invoices</title>
</asp:Content>

<asp:Content ID="BodyContent" ContentPlaceHolderID="BodyHolder" runat="server">
    <div>
       <!-- <asp:CheckBox ID="chkMatchByValue" runat="server" Text="Match By Value" Checked="true" />
        <asp:CheckBox ID="chkMatchByDate" runat="server" Text="Match By Date" Checked="true" />
        <asp:CheckBox ID="chkMatchByRemitterName" runat="server" Text="Match By Remitter Name"
            Checked="true" />-->
            <hr />
            <div>Select Remitter For Matching :
            <asp:DropDownList ID="ddlRemitter" runat="server" AutoPostBack="true" Width = "300" 
                    onselectedindexchanged="ddlRemitter_SelectedIndexChanged">
                    <asp:ListItem Value="0">Please Select Remitter</asp:ListItem>                    
                </asp:DropDownList>
             </div>
    </div>
  <%--  <hr />--%>

    <asp:UpdatePanel ID="upUnmatchedLists" runat="server" UpdateMode="Conditional">
        <ContentTemplate>

            <div class="formDiv" id="formMatchDiv">


<!--
               <div id="DivRoot" align="left">
            <div style="overflow: hidden;" id="DivHeaderRow">
            </div>

            <div style="overflow:scroll;" onscroll="OnScrollDiv(this)" id="DivMainContent">
       
       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Width="400"
                        HeaderStyle-BackColor="#ffc3e1" HeaderStyle-ForeColor="#800000" HeaderStyle-Font-Bold="true">
                        <EmptyDataTemplate>
                            <asp:Label ID="lblNoRows" runat="server" Text="There are no Invoices to be matched." />
                        </EmptyDataTemplate>
                        <Columns>
                            <asp:TemplateField HeaderText="Select">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("invoice_unique_id") %>'
                                        Visible="false" />
                                    <asp:CheckBox ID="chkSelect" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Invoice No" DataField="invoice_number" />
                            <asp:BoundField HeaderText="Date" DataField="date" />
                            <asp:BoundField HeaderText="Remitter" DataField="remitter_id" />
                            <asp:BoundField HeaderText="Amount" DataField="amount" />
                        </Columns>
                    </asp:GridView>
      
        </div>

        <div id="DivFooterRow" style="overflow:hidden">
        </div>
    </div>-->
            <table cellspacing="1" cellpadding="1" border="0" width="100%">
                <tr>
                    <td colspan="5">
               <!-- <span title="Invoice List" style="azimuth: left; position: absolute; top: 135px;
                    left: 200px; width: 450px;"> -->
                    <asp:Label ID="lblInvoiceList" runat="server" Text="Invoice List:" CssClass="lable"/>
                    <div style="height:380px; width:600px; overflow:auto;">
                    <asp:GridView ID="grdInvoice" runat="server" AutoGenerateColumns="False" Width="600"
                        HeaderStyle-BackColor="#222222" HeaderStyle-ForeColor="#6f788f" ForeColor="#333333"
                            HeaderStyle-Font-Bold="false" onrowdatabound="grdInvoice_RowDataBound">
                        <EmptyDataTemplate>
                            <asp:Label ID="lblNoRows" runat="server" Text="There are no Invoices to be matched." />
                        </EmptyDataTemplate>
                        <Columns>

                            <asp:TemplateField>
                                <HeaderTemplate >
                                    <input id ="SelectAllCheckBox"  type="checkbox" name="SelectAllCheckBox" style="azimuth: left; left: 0px;"  onclick="javascript:SelectAllInvoice(this)">
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("invoice_unique_id") %>' Visible="false" />
                                    <input id="chkSelect" type="checkbox" name="chk" runat="server"/>                        
                                </ItemTemplate>                   
                            </asp:TemplateField>
                           <%-- <asp:TemplateField HeaderText="Select">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("invoice_unique_id") %>'
                                        Visible="false" />
                                    <asp:CheckBox ID="chkSelect" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>--%>
                            <asp:BoundField HeaderText="Invoice No" DataField="invoice_number" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Date" DataField="date" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Remitter" DataField="remitter_id" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Amount(INR)" DataField="amount" HeaderStyle-Font-Bold = "false"/>
                        </Columns>
                        <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f"/>
                    </asp:GridView>
                    </div>
              <!--  </span> -->
                </td>
               <td colspan="5" align="left">
               <!-- <span title="Statement List" style="azimuth: right; position: absolute; top: 135px;
                    right: 200px; width: 450px;"> -->
                    <asp:Label ID="lblStatementList" runat="server" Text="Statement List:" CssClass="lable" />                    
                    <div style="height:380px; width:700px; overflow:auto;">
                    <asp:GridView ID="grdStatement" runat="server" AutoGenerateColumns="false" Width="600"
                        HeaderStyle-BackColor="silver" HeaderStyle-ForeColor="#6f788f" ForeColor="#333333"
                        HeaderStyle-Font-Bold="false" onrowdatabound="grdStatement_RowDataBound">
                        <EmptyDataTemplate>
                            <asp:Label ID="lblNoRows" runat="server" Text="There are no Statements to be matched." />
                        </EmptyDataTemplate>
                        <Columns>
                             <asp:TemplateField>
                                <HeaderTemplate>
                                    <input id ="SelectAllCheckBox" type="checkbox" name="SelectAllCheckBox" onclick="javascript:SelectAllStatement(this)">
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:Literal ID="ltlStatementUniqueID" runat="server" Text='<%# Eval("statement_unique_id") %>' Visible="false" />
                                        <input id="chkSelect"  type="checkbox" name="chk" runat="server"/>
                                    </ItemTemplate>
                            </asp:TemplateField>
                            <%--<asp:TemplateField HeaderText="Select">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlStatementUniqueID" runat="server" Text='<%# Eval("statement_unique_id") %>'
                                        Visible="false" />
                                    <asp:CheckBox ID="chkSelect" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>--%>
                            <asp:BoundField HeaderText="PaymentRef#/Cheque#" DataField="ref_no_or_cheque_no" HeaderStyle-Font-Bold = "false" />
                            <asp:BoundField HeaderText="Date" DataField="value_date" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Narration1" DataField="narration1" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Amount(INR)" DataField="amount" HeaderStyle-Font-Bold = "false"/>
                        </Columns>
                        <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f"/>
                    </asp:GridView>
                    </div>
             <!--   </span> -->
              </td>
                </tr>
               </table>
            </div>
            <div>
                <div>
                    <asp:Button ID="btnManualMatch" runat="server" Text="Mark Manual Match" OnClick="btnManualMatch_Click"
                     BorderStyle="Groove" BackColor="#101e45" ForeColor="#FFFFFF"/>
                    &nbsp;<asp:Button ID="btnAutoMatch" runat="server" Text="Auto Match By Amount" OnClick="btnAutoMatch_Click" />
                    &nbsp;
                    <asp:Button ID="btnAutoByRef" runat="server" Text="Auto Match By Amount/Ref" OnClick="btnAutoByRef_Click" />
                    &nbsp;
                    <asp:Button ID="btnAutoByDiscount" runat="server" Text="Auto Match By Discount" OnClick="btnAutoByDiscount_Click" />
                    &nbsp;
                    <asp:Button ID="btnAutoByPenalty" runat="server" Text="Auto Match By Penalty" OnClick="btnAutoByPenalty_Click" />
                    &nbsp;<asp:Button ID="btnSendToRemitter" runat="server" Text="Send to Remitter" OnClick="btnSendToRemitter_Click" />
                </div>
            <div id="pnlMatchList" runat="server" class="pnlMatchList">
                <span style="azimuth: center;">
                    <asp:Label ID="lblMatchList" runat="server" Text="List of Selected Invoice:Statement Matches:"  CssClass="lable"/>
                    <div style="height:400px; width:850px; overflow:auto; azimuth: center;">
                    <asp:GridView ID="grdMatchList" runat="server" AutoGenerateColumns="false" CssClass="formDiv"
                        HeaderStyle-BackColor="#555555" HeaderStyle-ForeColor="#6f788f" 
                            HeaderStyle-Font-Bold="false" onrowdatabound="grdMatchList_RowDataBound">
                        <EmptyDataTemplate>
                            <asp:Label ID="lblNoRows" runat="server" Text="There are no Invoice:Statement match selections." />
                        </EmptyDataTemplate>
                        <Columns>
                            <asp:TemplateField HeaderText="" Visible ="false">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("invoice_unique_id") %>'
                                        Visible="false" />
                                    <asp:Literal ID="ltlStatementUniqueID" runat="server" Text='<%# Eval("statement_unique_id") %>'
                                        Visible="false" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Invoice No" DataField="invoice_number" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Date" DataField="date" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Remitter" DataField="remitter_id" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Amount(INR)" DataField="amount" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="PaymentRef#/Cheque#" DataField="ref_no_or_cheque_no" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Date" DataField="value_date" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Narration1" DataField="narration1" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Amount(INR)" DataField="statement_amount" HeaderStyle-Font-Bold = "false"/>
                        </Columns>
                        <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f"/>
                    </asp:GridView>
                    </div>
                </span>
                <div class="formDiv" style="width: 22%; border: 0.1em solid #FFFFFF; background: #FFFFFF;">
                    <asp:Button ID="btnConfirmMatches" runat="server" Text="Confirm Matches" OnClick="btnConfirmMatches_Click"/>
                    <asp:Button ID="btnCancelMatches" runat="server" Text="Cancel" OnClick="btnCancelMatches_Click" />
                </div>
            </div>
            <div style="display: none">
                <asp:Button ID="btnManualPopup" runat="server" />
                
            </div>
          
            <ajax:ModalPopupExtender ID="ManualMatchConfirmationPopup" runat="server" PopupControlID="pnlMatchList"
                TargetControlID="btnManualPopup" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowScroll">
            </ajax:ModalPopupExtender>
           
            <div id="pnlRemitterList" runat="server" class="pnlMatchList">
                <span style="azimuth: center;">
                    <asp:Label ID="Label1" runat="server" Text="List of Selected Invoices to be sent to Remitter:"  CssClass="lable"/>
                    <div style="height:400px; width:850px; overflow:auto; azimuth: center;">
                    <asp:GridView ID="grdRemitter" runat="server" AutoGenerateColumns="false" CssClass="formDiv"
                        HeaderStyle-BackColor="#555555" HeaderStyle-ForeColor="#6f788f" 
                            HeaderStyle-Font-Bold="false" OnRowDataBound="grdRemitter_RowDataBound">
                        <EmptyDataTemplate>
                            <asp:Label ID="lblNoRows" runat="server" Text="There are no Invoice selections to be sent to Remitter." />
                        </EmptyDataTemplate>
                        <Columns>
                            <asp:TemplateField HeaderText="" Visible ="false">
                                <ItemTemplate>
                                    <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("invoice_unique_id") %>'
                                        Visible="false" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Invoice No" DataField="invoice_number" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Date" DataField="date" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Remitter" DataField="remitter_id" HeaderStyle-Font-Bold = "false"/>
                            <asp:BoundField HeaderText="Amount(INR)" DataField="amount" HeaderStyle-Font-Bold = "false"/>
                        </Columns>
                        <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f"/>
                    </asp:GridView>
                    </div>
                </span>
                <div class="formDiv" style="width: 22%; border: 0.1em solid #FFFFFF; background: #FFFFFF;">
                    <asp:Button ID="btnConfirmRemitter" runat="server" Text="Confirm" 
                        OnClick="btnConfirmRemitter_Click" />
                    <asp:Button ID="btnCancelRemitter" runat="server" Text="Cancel" 
                        OnClick="btnCancelRemitter_Click" />
                </div>
            </div>
            <div style="display: none">
                <asp:Button ID="btnRemitterPopup" runat="server" />
            </div>

            <ajax:ModalPopupExtender ID="RemitterConfirmationPopup" runat="server" PopupControlID="pnlRemitterList"
                TargetControlID="btnRemitterPopup" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowScroll">
            </ajax:ModalPopupExtender>

        </ContentTemplate>
        
    </asp:UpdatePanel>
    </div>

    <script type="text/javascript">
        function SelectAllStatement(CheckBoxControl) {
            if (CheckBoxControl.checked == true) {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('grdStatement') > -1)) {
                        document.forms[0].elements[i].checked = true;
                    }
                }
            }
            else {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') &&
                    (document.forms[0].elements[i].name.indexOf('grdStatement') > -1)) {
                        document.forms[0].elements[i].checked = false;
                    }
                }
            }
        }

        function SelectAllInvoice(CheckBoxControl) {
            if (CheckBoxControl.checked == true) {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('grdInvoice') > -1)) {
                        document.forms[0].elements[i].checked = true;
                    }
                }
            }
            else {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') &&
                    (document.forms[0].elements[i].name.indexOf('grdInvoice') > -1)) {
                        document.forms[0].elements[i].checked = false;
                    }
                }
            }
        }
    </script>
</asp:Content>
